home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / CIncludes / OSUtils.h < prev    next >
C/C++ Source or Header  |  1996-05-01  |  13KB  |  531 lines

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Contains:    OS Utilities Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0d3 on Copland DR1
  8.  
  9.      Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  10.  
  11.      Bugs?:        If you find a problem with this file, send the file and version
  12.                  information (from above) and the problem description to:
  13.  
  14.                      Internet:    apple.bugs@applelink.apple.com
  15.                      AppleLink:    APPLE.BUGS
  16.  
  17. */
  18. #ifndef __OSUTILS__
  19. #define __OSUTILS__
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. #ifndef __MIXEDMODE__
  25. #include <MixedMode.h>
  26. #endif
  27. #ifndef __MEMORY__
  28. #include <Memory.h>
  29. #endif
  30. #ifndef __PATCHES__
  31. #include <Patches.h>
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if PRAGMA_IMPORT_SUPPORTED
  39. #pragma import on
  40. #endif
  41.  
  42. #if PRAGMA_ALIGN_SUPPORTED
  43. #pragma options align=mac68k
  44. #endif
  45.  
  46.  
  47. enum {
  48.     useFree                        = 0,
  49.     useATalk                    = 1,
  50.     useAsync                    = 2,
  51.     useExtClk                    = 3,                            /*Externally clocked*/
  52.     useMIDI                        = 4,                            /* Machine Types */
  53.     envMac                        = -1,
  54.     envXL                        = -2,
  55.     envMachUnknown                = 0,
  56.     env512KE                    = 1,
  57.     envMacPlus                    = 2,
  58.     envSE                        = 3,
  59.     envMacII                    = 4,
  60.     envMacIIx                    = 5,
  61.     envMacIIcx                    = 6,
  62.     envSE30                        = 7,
  63.     envPortable                    = 8,
  64.     envMacIIci                    = 9,
  65.     envMacIIfx                    = 11,                            /* CPU types */
  66.     envCPUUnknown                = 0
  67. };
  68.  
  69.  
  70. enum {
  71.     env68000                    = 1,
  72.     env68010                    = 2,
  73.     env68020                    = 3,
  74.     env68030                    = 4,
  75.     env68040                    = 5,                            /* Keyboard types */
  76.     envUnknownKbd                = 0,
  77.     envMacKbd                    = 1,
  78.     envMacAndPad                = 2,
  79.     envMacPlusKbd                = 3,
  80.     envAExtendKbd                = 4,
  81.     envStandADBKbd                = 5,
  82.     envPrtblADBKbd                = 6,
  83.     envPrtblISOKbd                = 7,
  84.     envStdISOADBKbd                = 8,
  85.     envExtISOADBKbd                = 9,
  86.     false32b                    = 0,                            /*24 bit addressing error*/
  87.     true32b                        = 1,                            /*32 bit addressing error*/
  88.                                                                 /* result types for RelString Call */
  89.     sortsBefore                    = -1,                            /*first string < second string*/
  90.     sortsEqual                    = 0,                            /*first string = second string*/
  91.     sortsAfter                    = 1                                /*first string > second string*/
  92. };
  93.  
  94.  
  95. enum {
  96.                                                                 /* Toggle results */
  97.     toggleUndefined                = 0,
  98.     toggleOK                    = 1,
  99.     toggleBadField                = 2,
  100.     toggleBadDelta                = 3,
  101.     toggleBadChar                = 4,
  102.     toggleUnknown                = 5,
  103.     toggleBadNum                = 6,
  104.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  105.     toggleErr3                    = 7,
  106.     toggleErr4                    = 8,
  107.     toggleErr5                    = 9,                            /* Date equates */
  108.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  109.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  110.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  111.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  112.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  113.     validDateFields                = -1,
  114.     maxDateField                = 10,
  115.     eraMask                        = 0x0001,
  116.     yearMask                    = 0x0002,
  117.     monthMask                    = 0x0004,
  118.     dayMask                        = 0x0008,
  119.     hourMask                    = 0x0010,
  120.     minuteMask                    = 0x0020,
  121.     secondMask                    = 0x0040,
  122.     dayOfWeekMask                = 0x0080,
  123.     dayOfYearMask                = 0x0100,
  124.     weekOfYearMask                = 0x0200,
  125.     pmMask                        = 0x0400,
  126.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  127. };
  128.  
  129.  
  130. enum {
  131.     eraField                    = 0,
  132.     yearField                    = 1,
  133.     monthField                    = 2,
  134.     dayField                    = 3,
  135.     hourField                    = 4,
  136.     minuteField                    = 5,
  137.     secondField                    = 6,
  138.     dayOfWeekField                = 7,
  139.     dayOfYearField                = 8,
  140.     weekOfYearField                = 9,
  141.     pmField                        = 10,
  142.     res1Field                    = 11,
  143.     res2Field                    = 12,
  144.     res3Field                    = 13
  145. };
  146.  
  147. typedef SignedByte LongDateField;
  148.  
  149. enum {
  150.     dummyType                    = 0,
  151.     vType                        = 1,
  152.     ioQType                        = 2,
  153.     drvQType                    = 3,
  154.     evType                        = 4,
  155.     fsQType                        = 5,
  156.     sIQType                        = 6,
  157.     dtQType                        = 7,
  158.     nmType                        = 8
  159. };
  160.  
  161. typedef SignedByte QTypes;
  162. struct SysParmType {
  163.     UInt8                             valid;
  164.     UInt8                             aTalkA;
  165.     UInt8                             aTalkB;
  166.     UInt8                             config;
  167.     short                             portA;
  168.     short                             portB;
  169.     long                             alarm;
  170.     short                             font;
  171.     short                             kbdPrint;
  172.     short                             volClik;
  173.     short                             misc;
  174. };
  175. typedef struct SysParmType SysParmType;
  176.  
  177. typedef SysParmType *SysPPtr;
  178. struct QElem {
  179.     struct QElem *                    qLink;
  180.     short                             qType;
  181.     short                             qData[1];
  182. };
  183. typedef struct QElem QElem;
  184.  
  185. typedef QElem *QElemPtr;
  186. struct QHdr {
  187.     short                             qFlags;
  188.     QElemPtr                         qHead;
  189.     QElemPtr                         qTail;
  190. };
  191. typedef struct QHdr QHdr;
  192.  
  193. typedef QHdr *QHdrPtr;
  194. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  195. /*
  196.         This ProcPtr uses register based parameters on the 68k and cannot
  197.         be written in or called from a high-level language without the help of
  198.         mixed mode or assembly glue.
  199.  
  200.             typedef pascal void (*DeferredTaskProcPtr)(long dtParam);
  201.  
  202. */
  203.  
  204. #if GENERATINGCFM
  205. typedef UniversalProcPtr DeferredTaskUPP;
  206. #else
  207. typedef Register68kProcPtr DeferredTaskUPP;
  208. #endif
  209. struct DeferredTask {
  210.     QElemPtr                         qLink;
  211.     short                             qType;
  212.     short                             dtFlags;
  213.     DeferredTaskUPP                 dtAddr;
  214.     long                             dtParam;
  215.     long                             dtReserved;
  216. };
  217. typedef struct DeferredTask DeferredTask;
  218.  
  219. typedef DeferredTask *DeferredTaskPtr;
  220. #endif
  221. struct MachineLocation {
  222.     Fract                             latitude;
  223.     Fract                             longitude;
  224.     union {
  225.         SInt8                             dlsDelta;                /* signed byte; daylight savings delta */
  226.         long                             gmtDelta;                /* use low 24-bits only */
  227.     }                                 u;
  228. };
  229. typedef struct MachineLocation MachineLocation;
  230.  
  231. struct DateTimeRec {
  232.     short                             year;
  233.     short                             month;
  234.     short                             day;
  235.     short                             hour;
  236.     short                             minute;
  237.     short                             second;
  238.     short                             dayOfWeek;
  239. };
  240. typedef struct DateTimeRec DateTimeRec;
  241.  
  242. typedef wide LongDateTime;
  243. union LongDateCvt {
  244.     wide                             c;
  245.     struct {
  246.         UInt32                             lHigh;
  247.         UInt32                             lLow;
  248.     }                                 hl;
  249. };
  250. typedef union LongDateCvt LongDateCvt;
  251.  
  252. union LongDateRec {
  253.     struct {
  254.         short                             era;
  255.         short                             year;
  256.         short                             month;
  257.         short                             day;
  258.         short                             hour;
  259.         short                             minute;
  260.         short                             second;
  261.         short                             dayOfWeek;
  262.         short                             dayOfYear;
  263.         short                             weekOfYear;
  264.         short                             pm;
  265.         short                             res1;
  266.         short                             res2;
  267.         short                             res3;
  268.     }                                 ld;
  269.     short                             list[14];                    /*Index by LongDateField!*/
  270.     struct {
  271.         short                             eraAlt;
  272.         DateTimeRec                     oldDate;
  273.     }                                 od;
  274. };
  275. typedef union LongDateRec LongDateRec;
  276.  
  277. typedef SInt8 DateDelta;
  278. struct TogglePB {
  279.     long                             togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  280.     ResType                         amChars;                    /*from 'itl0', but uppercased*/
  281.     ResType                         pmChars;                    /*from 'itl0', but uppercased*/
  282.     long                             reserved[4];
  283. };
  284. typedef struct TogglePB TogglePB;
  285.  
  286. typedef short ToggleResults;
  287. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  288.  
  289. enum {
  290.     uppDeferredTaskProcInfo = kRegisterBased
  291.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(long)))
  292. };
  293.  
  294. #if GENERATINGCFM
  295. #define NewDeferredTaskProc(userRoutine)        \
  296.         (DeferredTaskUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  297. #else
  298. #define NewDeferredTaskProc(userRoutine)        \
  299.         ((DeferredTaskUPP) (userRoutine))
  300. #endif
  301.  
  302. #if GENERATINGCFM
  303. #define CallDeferredTaskProc(userRoutine, dtParam)        \
  304.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDeferredTaskProcInfo, (dtParam))
  305. #else
  306. /* (*DeferredTaskUPP) cannot be called from a high-level language without the Mixed Mode Manager */
  307. #endif
  308. #endif
  309. extern pascal void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
  310.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  311.  
  312. extern pascal void LongSecondsToDate(LongDateTime *lSecs, LongDateRec *lDate)
  313.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  314.  
  315. extern pascal ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
  316.  FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  317.  
  318. extern pascal short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
  319.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  320.  
  321. extern pascal Boolean IsMetric(void )
  322.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  323.  
  324. extern pascal SysPPtr GetSysPPtr(void )
  325.  THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  326.  
  327.  
  328. #if GENERATING68K && !GENERATINGCFM
  329. #pragma parameter __D0 ReadDateTime(__A0)
  330. #endif
  331. extern pascal OSErr ReadDateTime(unsigned long *time)
  332.  ONEWORDINLINE(0xA039);
  333.  
  334.  
  335. #if GENERATING68K && !GENERATINGCFM
  336. #pragma parameter GetDateTime(__A0)
  337. #endif
  338. extern pascal void GetDateTime(unsigned long *secs)
  339.  TWOWORDINLINE(0x20B8, 0x020C);
  340.  
  341.  
  342. #if GENERATING68K && !GENERATINGCFM
  343. #pragma parameter __D0 SetDateTime(__D0)
  344. #endif
  345. extern pascal OSErr SetDateTime(unsigned long time)
  346.  ONEWORDINLINE(0xA03A);
  347.  
  348.  
  349. #if GENERATING68K && !GENERATINGCFM
  350. #pragma parameter SetTime(__A0)
  351. #endif
  352. extern pascal void SetTime(const DateTimeRec *d)
  353.  TWOWORDINLINE(0xA9C7, 0xA03A);
  354.  
  355.  
  356. #if GENERATING68K && !GENERATINGCFM
  357. #pragma parameter GetTime(__A0)
  358. #endif
  359. extern pascal void GetTime(DateTimeRec *d)
  360.  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  361.  
  362. extern pascal void DateToSeconds(const DateTimeRec *d, unsigned long *secs);
  363.  
  364.  
  365. #if GENERATING68K && !GENERATINGCFM
  366. #pragma parameter SecondsToDate(__D0, __A0)
  367. #endif
  368. extern pascal void SecondsToDate(unsigned long secs, DateTimeRec *d)
  369.  ONEWORDINLINE(0xA9C6);
  370.  
  371. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  372.  
  373. #if GENERATING68K && !GENERATINGCFM
  374. #pragma parameter __D0 DTInstall(__A0)
  375. #endif
  376. extern pascal OSErr DTInstall(DeferredTaskPtr dtTaskPtr)
  377.  ONEWORDINLINE(0xA082);
  378.  
  379. #endif
  380. #if GENERATINGPOWERPC
  381. #define GetMMUMode() ((char)true32b)
  382. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  383. #else
  384. extern pascal SInt8 GetMMUMode(void)
  385.  TWOWORDINLINE(0x1EB8, 0x0CB2);
  386.  
  387.  
  388. #if GENERATING68K && !GENERATINGCFM
  389. #pragma parameter SwapMMUMode(__A0)
  390. #endif
  391. extern pascal void SwapMMUMode(SInt8 *mode)
  392.  THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  393.  
  394. #endif
  395.  
  396. #if GENERATING68K && !GENERATINGCFM
  397. #pragma parameter Delay(__A0, __A1)
  398. #endif
  399. extern pascal void Delay(long numTicks, long *finalTicks)
  400.  TWOWORDINLINE(0xA03B, 0x2280);
  401.  
  402. extern pascal OSErr WriteParam(void );
  403.  
  404.  
  405. #if GENERATING68K && !GENERATINGCFM
  406. #pragma parameter Enqueue(__A0, __A1)
  407. #endif
  408. extern pascal void Enqueue(QElemPtr qElement, QHdrPtr qHeader)
  409.  ONEWORDINLINE(0xA96F);
  410.  
  411.  
  412. #if GENERATING68K && !GENERATINGCFM
  413. #pragma parameter __D0 Dequeue(__A0, __A1)
  414. #endif
  415. extern pascal OSErr Dequeue(QElemPtr qElement, QHdrPtr qHeader)
  416.  ONEWORDINLINE(0xA96E);
  417.  
  418.  
  419. #if GENERATING68K && !GENERATINGCFM
  420. #pragma parameter __D0 SetCurrentA5
  421. #endif
  422. extern pascal long SetCurrentA5(void )
  423.  THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  424.  
  425.  
  426. #if GENERATING68K && !GENERATINGCFM
  427. #pragma parameter __D0 SetA5(__D0)
  428. #endif
  429. extern pascal long SetA5(long newA5)
  430.  ONEWORDINLINE(0xC18D);
  431.  
  432.  
  433. #if GENERATING68K && !GENERATINGCFM
  434. #pragma parameter __D0 InitUtil
  435. #endif
  436. extern pascal OSErr InitUtil(void )
  437.  ONEWORDINLINE(0xA03F);
  438.  
  439. #if GENERATINGPOWERPC
  440. extern pascal void MakeDataExecutable(void *baseAddress, unsigned long length);
  441.  
  442. #endif
  443. #if GENERATING68K
  444. extern pascal Boolean SwapInstructionCache(Boolean cacheEnable);
  445.  
  446. extern pascal void FlushInstructionCache(void )
  447.  TWOWORDINLINE(0x7001, 0xA098);
  448.  
  449. extern pascal Boolean SwapDataCache(Boolean cacheEnable);
  450.  
  451. extern pascal void FlushDataCache(void )
  452.  TWOWORDINLINE(0x7003, 0xA098);
  453.  
  454. extern pascal void FlushCodeCache(void )
  455.  ONEWORDINLINE(0xA0BD);
  456.  
  457.  
  458. #if GENERATING68K && !GENERATINGCFM
  459. #pragma parameter FlushCodeCacheRange(__A0, __A1)
  460. #endif
  461. extern pascal void FlushCodeCacheRange(void *address, unsigned long count)
  462.  TWOWORDINLINE(0x7009, 0xA098);
  463.  
  464. #endif
  465.  
  466. #if GENERATING68K && !GENERATINGCFM
  467. #pragma parameter ReadLocation(__A0)
  468. #endif
  469. extern pascal void ReadLocation(MachineLocation *loc)
  470.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  471.  
  472.  
  473. #if GENERATING68K && !GENERATINGCFM
  474. #pragma parameter WriteLocation(__A0)
  475. #endif
  476. extern pascal void WriteLocation(const MachineLocation *loc)
  477.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  478.  
  479. #if OLDROUTINENAMES
  480. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  481. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  482. #define IUMetric() IsMetric()
  483. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  484. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  485. #endif
  486. #if OLDROUTINELOCATIONS
  487. /* Environs Equates */
  488.  
  489. enum {
  490.     curSysEnvVers                = 2                                /*Updated to equal latest SysEnvirons version*/
  491. };
  492.  
  493. struct SysEnvRec {
  494.     short                             environsVersion;
  495.     short                             machineType;
  496.     short                             systemVersion;
  497.     short                             processor;
  498.     Boolean                         hasFPU;
  499.     Boolean                         hasColorQD;
  500.     short                             keyBoardType;
  501.     short                             atDrvrVersNum;
  502.     short                             sysVRefNum;
  503. };
  504. typedef struct SysEnvRec SysEnvRec;
  505.  
  506. #if FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED
  507.  
  508. #if GENERATING68K && !GENERATINGCFM
  509. #pragma parameter __D0 SysEnvirons(__D0, __A0)
  510. #endif
  511. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld)
  512.  ONEWORDINLINE(0xA090);
  513.  
  514. #endif
  515. #endif
  516.  
  517. #if PRAGMA_ALIGN_SUPPORTED
  518. #pragma options align=reset
  519. #endif
  520.  
  521. #if PRAGMA_IMPORT_SUPPORTED
  522. #pragma import off
  523. #endif
  524.  
  525. #ifdef __cplusplus
  526. }
  527. #endif
  528.  
  529. #endif /* __OSUTILS__ */
  530.  
  531.